<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="报工类型" prop="feedbackType">
        <el-select v-model="queryParams.feedbackType" placeholder="请选择报工类型" clearable>
          <el-option v-for="dict in dict.type.mes_feedback_type" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="工作站名称" prop="workstationName">
        <el-input
          v-model="queryParams.workstationName"
          placeholder="请输入工作站名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="生产工单编号" prop="workorderCode">
        <el-input v-model="queryParams.workorderCode" placeholder="请输入生产工单编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品编码" prop="itemCode">
        <el-input v-model="queryParams.itemCode" placeholder="请输入产品编码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品名称" prop="itemName">
        <el-input v-model="queryParams.itemName" placeholder="请输入产品名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="报工人" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入报工人名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="记录人" prop="recordUser">
        <el-input
          v-model="queryParams.recordUser"
          placeholder="请输入记录人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="班组" prop="workGroup">
        <el-select v-model="queryParams.workGroup" placeholder="请选择班组" clearable>
          <el-option v-for="dict in dict.type.mes_work_group" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option v-for="dict in dict.type.mes_order_status" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker v-model="daterangeCreateTime" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-radio-group v-model="queryParams.reportDepartment" size="mini">
          <el-radio-button label="0">印刷</el-radio-button>
          <el-radio-button label="1">制袋</el-radio-button>
        </el-radio-group>
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['mes:pro:feedback:add']">新增</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['mes:pro:feedback:edit']"
        >修改</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['mes:pro:feedback:remove']">删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="feedbackList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="报表编号" align="center" prop="recordId" />
      <el-table-column label="报工类型" align="center" prop="feedbackType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_feedback_type" :value="scope.row.feedbackType" />
        </template>
      </el-table-column>
      <el-table-column label="报工部门" align="center" prop="reportDepartment">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_report_department" :value="scope.row.reportDepartment" />
        </template>
      </el-table-column>
      <el-table-column label="班组" align="center" prop="workGroup">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_work_group" :value="scope.row.workGroup" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="设备类型ID" align="center" prop="machineryId" /> -->
      <el-table-column label="设备类型编码" align="center" prop="machineryCode" />
      <el-table-column label="设备类型名称" align="center" prop="machineryName" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_order_status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="工作站ID" align="center" prop="workstationId" />
      <el-table-column label="工作站编号" align="center" prop="workstationCode" />
      <el-table-column label="工作站名称" align="center" prop="workstationName" />-->
      <!-- <el-table-column label="生产工单ID" align="center" prop="workorderId" /> -->
      <el-table-column label="生产工单编号" align="center" prop="workorderCode" />
      <el-table-column label="生产工单名称" align="center" prop="workorderName" />
      <!-- <el-table-column label="生产任务ID" align="center" prop="taskId" /> -->
      <el-table-column label="生产任务编号" align="center" prop="taskCode" />
      <!-- <el-table-column label="产品物料ID" align="center" prop="itemId" /> -->
      <el-table-column label="产品编码" align="center" prop="itemCode" />
      <el-table-column label="产品s名称" align="center" prop="itemName" />
      <el-table-column label="单位" align="center" prop="unitOfMeasure" />
      <el-table-column label="规格型号" align="center" prop="specification" />
      <el-table-column label="排产数量" align="center" prop="quantity" />
      <el-table-column label="本次报工数量" align="center" prop="quantityFeedback" />
      <!-- <el-table-column label="合格品数量" align="center" prop="quantityQualified" /> -->
      <!-- <el-table-column label="不良品数量" align="center" prop="quantityUnquanlified" /> -->
      <!-- <el-table-column label="报工用户名" align="center" prop="userName" /> -->
      <el-table-column label="报工人姓名" align="center" prop="nickName" />
      <!-- <el-table-column label="报工途径" align="center" prop="feedbackChannel" /> -->
      <el-table-column label="报工时间" align="center" prop="feedbackTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.feedbackTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="记录人" align="center" prop="recordUser" /> -->
      <el-table-column label="记录人姓名" align="center" prop="recordNick" />
      <el-table-column label="原纸卷号" align="center" prop="rawPaperRollNumber" v-if="queryParams.reportDepartment == 0" />
      <el-table-column label="生产米数" align="center" prop="productionLength" v-if="queryParams.reportDepartment == 0" />
      <el-table-column label="生产个数" align="center" prop="productionQuantity" v-if="queryParams.reportDepartment == 0" />
      <el-table-column label="预印批号(卷号)" align="center" prop="preprintBatchNumber" v-if="queryParams.reportDepartment == 1" />
      <el-table-column label="预印数(张)" align="center" prop="preprintQuantity" v-if="queryParams.reportDepartment == 1" />
      <el-table-column label="制袋数(个)" align="center" prop="bagProductionQuantity" v-if="queryParams.reportDepartment == 1" />
      <el-table-column label="料头(KG)" align="center" prop="materialHeadWeight" v-if="queryParams.reportDepartment == 1" />
      <el-table-column label="返修数" align="center" prop="reworkNumber" v-if="queryParams.reportDepartment == 1" />
      <el-table-column label="印刷废品数" align="center" prop="printingWasteNumber" v-if="queryParams.reportDepartment == 1" />
      <el-table-column label="制袋废品" align="center" prop="bagWasteNumber" v-if="queryParams.reportDepartment == 1" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" fixed="right" align="center" width="100px" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-check" v-if="scope.row.status =='APPROVING'" @click="handleExecute(scope.row)" v-hasPermi="['mes:wm:feedback:push']">报工</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['mes:pro:feedback:edit']" v-if="scope.row.status =='PREPARE'|| scope.row.status =='APPROVING'">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['mes:pro:feedback:remove']" v-if="scope.row.status =='PREPARE'">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改生产报工记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="960px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="报工类型" prop="feedbackType">
              <el-select v-model="form.feedbackType" placeholder="请选择报工类型">
                <el-option v-for="dict in dict.type.mes_feedback_type" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="生产工单" prop="workorderCode">
              <el-input v-model="form.workorderCode" disabled placeholder="请选择生产工单">
                <el-button slot="append" icon="el-icon-search" @click="handleWorkorderSelect"></el-button>
              </el-input>
            </el-form-item>
            <WorkorderSelect ref="woSelect" @onSelected="onWorkorderSelected"></WorkorderSelect>
          </el-col>
          <!-- <el-col :span="8">
            <el-form-item label="工作站名称" prop="workstationName">
              <el-input v-model="form.workstationName" disabled placeholder="请输入工作站名称" >
                <el-button slot="append" icon="el-icon-search" @click="handleWorkstationSelect"></el-button>
              </el-input>
            </el-form-item>
            <WorkstationSelect ref="wsSelect"  @onSelected="onWorkstationSelected"> </WorkstationSelect>
          </el-col>-->
          <el-col :span="8">
            <el-form-item label="设备名称" prop="machineryName">
              <el-input v-model="form.machineryName" disabled placeholder="请选择设备">
                <el-button slot="append" icon="el-icon-search" @click="handleMachinerySelect"></el-button>
              </el-input>
            </el-form-item>
            <MachinerySelect ref="machinerySelect" @onSelected="onMachinerySelect"></MachinerySelect>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="产品编码" prop="itemCode">
              <el-input v-model="form.itemCode" placeholder="选择工单后同步" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="报工部门">
              <el-radio-group v-model="form.reportDepartment">
                <el-radio v-for="dict in dict.type.mes_report_department" :key="dict.value" :label="parseInt(dict.value)">{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="班组">
              <el-radio-group v-model="form.workGroup">
                <el-radio v-for="dict in dict.type.mes_work_group" :key="dict.value" :label="dict.value">{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>

          <!-- <el-col :span="8">
            <el-form-item label="单位" prop="unitOfMeasure">
              <el-input v-model="form.unitOfMeasure" disabled />
            </el-form-item>
          </el-col>-->
        </el-row>
        <!-- 印刷字段 -->
        <el-row v-if="form.reportDepartment == 0">
          <el-col :span="8">
            <el-form-item label="原纸(卷号)" prop="rawPaperRollNumber">
              <el-input v-model="form.rawPaperRollNumber" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="生产米数" prop="productionLength">
              <el-input-number :min="0" :precision="2" v-model="form.productionLength" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="生产个数" prop="productionQuantity">
              <el-input-number :min="0" v-model="form.productionQuantity" />
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 制袋字段 -->
        <el-row v-if="form.reportDepartment == 1">
          <el-col :span="8">
            <el-form-item label="预印批号(卷号)" prop="preprintBatchNumber">
              <el-input v-model="form.preprintBatchNumber" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="预印张数(张)" prop="preprintQuantity">
              <el-input-number :min="0" v-model="form.preprintQuantity" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="制袋数(个)" prop="bagProductionQuantity">
              <el-input-number :min="0" v-model="form.bagProductionQuantity" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="form.reportDepartment == 1">
          <el-col :span="8">
            <el-form-item label="料头(KG)" prop="materialHeadWeight">
              <el-input-number :min="0" :precision="2" v-model="form.materialHeadWeight" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="返修" prop="reworkNumber">
              <el-input-number :min="0" v-model="form.reworkNumber" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="印刷废品" prop="printingWasteNumber">
              <el-input-number :min="0" v-model="form.printingWasteNumber" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="form.reportDepartment == 1">
          <el-col :span="8">
            <el-form-item label="制袋废品" prop="bagWasteNumber">
              <el-input-number :min="0" v-model="form.bagWasteNumber" />
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-row>
          <el-col :span="24">
            <el-form-item label="规格型号" prop="specification">
               <el-link type="primary" :underline="false" @click="openSpc()">规格详情</el-link>
              <el-input v-model="form.specification" type="textarea" disabled />
            </el-form-item>
          </el-col>
        </el-row>-->
        <!-- <el-row>
          <el-col :span="8">
            <el-form-item label="报工数量" prop="quantityFeedback">
              <el-input v-model="form.quantityFeedback" />
              <el-input-number :min="0" @change="handleQuantityChanged" v-model="form.quantityFeedback" placeholder="请输入报工总数量" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="合格品数量" prop="quantityQualified">
              <el-input disabled v-model="form.quantityQualified" />
              <el-input-number :min="0" readonly="readonly" v-model="form.quantityQualified" placeholder="请输入合格品数量" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="不良品数量" prop="quantityUnquanlified">
              <el-input-number :min="0" @change="handleQuantityChanged" v-model="form.quantityUnquanlified" placeholder="请输入不良品数量" />
            </el-form-item>
          </el-col>
        </el-row>-->
        <el-row>
          <el-col :span="8">
            <el-form-item label="报工人" prop="nickName">
              <el-input v-model="form.nickName" placeholder="请选择报工人">
                <el-button slot="append" @click="handleUserSelect" icon="el-icon-search"></el-button>
              </el-input>
            </el-form-item>
            <UserSingleSelect ref="userSelect" @onSelected="onUserSelected"></UserSingleSelect>
          </el-col>
          <el-col :span="8">
            <el-form-item label="报工时间" prop="feedbackTime">
              <el-date-picker clearable v-model="form.feedbackTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择报工时间"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="审核人" prop="recordNick">
              <el-input v-model="form.recordNick" placeholder="请选择审核人">
                <el-button slot="append" @click="handleUser2Select" icon="el-icon-search"></el-button>
              </el-input>
            </el-form-item>
            <UserSingleSelect ref="user2Select" @onSelected="onUser2Selected"></UserSingleSelect>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel" v-if="optType =='view' || form.status !='PREPARE' ">返回</el-button>
        <el-button type="primary" @click="submitForm" v-if="form.status =='PREPARE' && optType !='view' ">保 存</el-button>
        <el-button type="success" @click="handleFinish" v-if="form.status =='PREPARE' && optType !='view'  && form.recordId != null">提交审批</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 规格属性展示框 -->
    <el-dialog title="规格属性列表" :visible.sync="dialogTableVisible" width="500px" append-to-body>
      <el-table :data="specificationData">
        <!-- <el-table-column v-for="item in form.specification" property="attrValue" :label="item.attrName" width="150"></el-table-column> -->
        <el-table-column property="attrName" label="规格名" width="150"></el-table-column>
        <el-table-column property="attrValue" label="规格值" width="200"></el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import {
  listFeedback,
  getFeedback,
  delFeedback,
  addFeedback,
  updateFeedback,
  execute,
} from "@/api/mes/pro/feedback";
import WorkorderSelect from "@/components/workorderSelect/single.vue";
import WorkstationSelect from "@/components/workstationSelect/simpletableSingle.vue";
import UserSingleSelect from "@/components/userSelect/single.vue";
import MachinerySelect from "@/components/machinerySelect/single.vue";
export default {
  name: "Feedback",
  components: {
    WorkorderSelect,
    WorkstationSelect,
    UserSingleSelect,
    MachinerySelect,
  },
  dicts: [
    "mes_order_status",
    "mes_feedback_type",
    "mes_work_group",
    "mes_report_department",
  ],
  data() {
    return {
      optType: undefined,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 生产报工记录表格数据
      feedbackList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 选中规格属性数据
      specificationData: [],
      // 是否显示规格详情弹出层
      dialogTableVisible: false,
      // 创建时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        feedbackType: null,
        workstationId: null,
        workstationCode: null,
        workstationName: null,
        workorderId: null,
        workorderCode: null,
        workorderName: null,
        taskId: null,
        taskCode: null,
        itemId: null,
        itemCode: null,
        itemName: null,
        unitOfMeasure: null,
        specification: null,
        quantity: null,
        quantityFeedback: null,
        quantityQualified: null,
        quantityUnquanlified: null,
        userName: null,
        nickName: null,
        feedbackChannel: null,
        feedbackTime: null,
        recordUser: null,
        recordNick: null,
        status: null,
        reportDepartment: "0",
        workGroup: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        feedbackType: [
          { required: true, message: "报工类型不能为空", trigger: "change" },
        ],
        workstationName: [
          { required: true, message: "工作站不能为空", trigger: "blur" },
        ],
        workorderCode: [
          { required: true, message: "生产工单不能为空", trigger: "blur" },
        ],
        quantityQualified: [
          { required: true, message: "请输入合格品数量", trigger: "blur" },
        ],
        quantityUnquanlified: [
          { required: true, message: "请输入不合格品数量", trigger: "blur" },
        ],
        nickName: [
          { required: true, message: "请选择报工人", trigger: "blur" },
        ],
        feedbackTime: [
          { required: true, message: "请选择报工时间", trigger: "blur" },
        ],
      },
    };
  },
  watch: {
    "form.reportDepartment"(newVal, oldVal) {
      if (newVal) {
        this.form.rawPaperRollNumber = null;
        this.form.productionLength = null;
        this.form.productionQuantity = null;
      } else {
        this.form.preprintBatchNumber = null;
        this.form.preprintQuantity = null;
        this.form.bagProductionQuantity = null;
        this.form.materialHeadWeight = null;
        this.form.reworkNumber = null;
        this.form.printingWasteNumber = null;
        this.form.bagWasteNumber = null;
      }
    },
    "queryParams.reportDepartment"(newVal, oldVal) {
      this.getList();
    },
  },
  created() {
    this.getList();
  },
  methods: {
    // 规格属性详情弹出框
    openSpc(row) {
      this.specificationData = null;
      this.dialogTableVisible = true;
      if (null != row && "" != row) {
        this.specificationData = JSON.parse(row);
      } else {
        this.specificationData = JSON.parse(this.form.specification);
      }
    },
    /** 查询生产报工记录列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateTime && "" != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] =
          this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listFeedback(this.queryParams).then((response) => {
        this.feedbackList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        recordId: null,
        feedbackType: null,
        workstationId: null,
        workstationCode: null,
        workstationName: null,
        workorderId: null,
        workorderCode: null,
        workorderName: null,
        taskId: null,
        taskCode: null,
        itemId: null,
        itemCode: null,
        itemName: null,
        specification: null,
        quantity: null,
        quantityFeedback: null,
        quantityQualified: null,
        quantityUnquanlified: null,
        userName: null,
        nickName: null,
        feedbackChannel: null,
        feedbackTime: new Date(),
        recordUser: null,
        recordNick: null,
        status: "PREPARE",
        reportDepartment: 0,
        workGroup: "A",
        rawPaperRollNumber: null,
        productionLength: null,
        productionQuantity: null,
        preprintBatchNumber: null,
        preprintQuantity: null,
        bagProductionQuantity: null,
        materialHeadWeight: null,
        reworkNumber: null,
        printingWasteNumber: null,
        bagWasteNumber: null,
        machineryId: null,
        machineryCode: null,
        machineryName: null,
        remark: null,
        attr1: null,
        attr2: null,
        attr3: null,
        attr4: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    handleQuantityChanged() {
      this.form.quantityQualified =
        this.form.quantityFeedback - this.form.quantityUnquanlified;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.daterangeCreateTime = [];
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.recordId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加生产报工记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const recordId = row.recordId || this.ids;
      getFeedback(recordId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改生产报工记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.bagProductionQuantity) {
            this.form.quantityFeedback = this.form.bagProductionQuantity;
            this.form.quantityQualified = this.form.bagProductionQuantity;
            this.form.quantityUnquanlified = 0;
          } else {
            this.form.quantityFeedback = this.form.productionQuantity;
            this.form.quantityQualified = this.form.productionQuantity;
            this.form.quantityUnquanlified = 0;
          }
          if (this.form.recordId != null) {
            updateFeedback(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFeedback(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    handleFinish() {
      this.form.status = "APPROVING";
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.recordId != null) {
            updateFeedback(this.form).then((response) => {
              this.$modal.msgSuccess("提交审批成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    //执行
    handleExecute(row) {
      const recordIds = row.recordId || this.ids;
      this.$modal
        .confirm("确认执行报工？")
        .then(function () {
          return execute(recordIds); //执行报工
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("执行成功");
        })
        .catch(() => {});
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const recordIds = row.recordId || this.ids;
      this.$modal
        .confirm('是否确认删除生产报工记录编号为"' + recordIds + '"的数据项？')
        .then(function () {
          return delFeedback(recordIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "pro/feedback/export",
        {
          ...this.queryParams,
        },
        `feedback_${new Date().getTime()}.xlsx`
      );
    },
    //选择生产工单
    handleWorkorderSelect() {
      this.$refs.woSelect.showFlag = true;
    },
    onWorkorderSelected(row) {
      if (row != undefined && row != null) {
        this.form.workorderId = row.workorderId;
        this.form.workorderCode = row.workorderCode;
        this.form.workorderName = row.workorderName;
        this.form.itemId = row.productId;
        this.form.itemCode = row.productCode;
        this.form.itemName = row.productName;
        this.form.specification = row.productSpc;
        this.form.unitOfMeasure = row.unitOfMeasure;
      }
    },
    handleWorkstationSelect() {
      this.$refs.wsSelect.showFlag = true;
    },
    onWorkstationSelected(row) {
      if (row != undefined && row != null) {
        this.form.workstationId = row.workstationId;
        this.form.workstationCode = row.workstationCode;
        this.form.workstationName = row.workstationName;
      }
    },
    // 选择设备
    handleMachinerySelect() {
      this.$refs.machinerySelect.showFlag = true;
    },
    // 选中设备回调
    onMachinerySelect(row) {
      console.log(row);
      if (row) {
        this.form.machineryId = row.machineryId;
        this.form.machineryName = row.machineryName;
        this.form.machineryCode = row.machineryCode;
      }
    },
    //点击人员选择按钮
    handleUserSelect() {
      this.$refs.userSelect.showFlag = true;
    },
    //人员选择返回
    onUserSelected(row) {
      this.form.nickName = row.nickName;
      this.form.userName = row.userName;
    },
    //点击人员选择按钮
    handleUser2Select() {
      this.$refs.user2Select.showFlag = true;
    },
    //人员选择返回
    onUser2Selected(row) {
      this.form.recordUser = row.userName;
      this.form.recordNick = row.nickName;
    },
  },
};
</script>
